#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
    int i;
    int seed = 500;
    int numPlayer = 2;
    int r, handCount;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;

	int councilRoom[MAX_HAND];
	for (i = 0; i < MAX_HAND; i++) {
		councilRoom[i] = council_room;
	}

	memset(&G, 23, sizeof(struct gameState));   // clear the game state
	r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
	G.handCount[0] = 5; //set number of cards in hand for player 0
	G.handCount[1] = 5; //set number of cards in hand for player 1

	#if (NOISY_TEST == 1)
		printf("P0 %d cards, %d buys | P1 %d cards\n", G.handCount[0], G.numBuys, G.handCount[1]);
		printf("TESTING COUNCIL_ROOM WITH CARDEFFECT\n");
	#endif

	for (i = 0; i < 5; i++) { //test three times, player 1's turn every time
		cardEffect(council_room, 0, -1, -1, &G, -1, 0); // play the card outright from thin air (not in the player's hand)

		#if (NOISY_TEST == 1)
			printf("P0 %d cards, %d buys | P1 %d cards\n", G.handCount[0], G.numBuys, G.handCount[1]);
		#endif
	}
	printf("\n");

	memset(&G, 23, sizeof(struct gameState));   // clear the game state
	r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
	G.handCount[0] = 5; //set number of cards in hand for player 0
	G.handCount[1] = 5; //set number of cards in hand for player 1
	G.numActions = 5; // normally starts at 1,
	i = G.numActions;

	#if (NOISY_TEST == 1)	
		printf("P0 %d cards, %d buys | P1 %d cards\n", G.handCount[0], G.numBuys, G.handCount[1]);
		printf("TESTING COUNCIL_ROOM BY PLAYING FROM HAND\n");
	#endif

	while (i != 0) { // while there are still actions left
		memcpy(G.hand[0], councilRoom, sizeof(int) * G.handCount[0]);  // sets all cards in player 1's hand to council_room
		playCard(0, -1, -1, -1, &G); // plays a council_room from the hand, +4 cards +1 buy
		printf("P0 %d cards, %d buys | P1 %d cards\n", G.handCount[0], G.numBuys, G.handCount[1]);
		i = G.numActions; //playCard automatically decrements the number of actions
	}

    printf("\nAll council_room tests completed!\n");

    return 0;
}
